package sanrenxing.dayEnd.backRepertoryTotal.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sanrenxing.dayEnd.backRepertoryTotal.dao.StocksectorDao;
import sanrenxing.dayEnd.backRepertoryTotal.domain.Stocksector;
import sanrenxing.dayEnd.backRepertoryTotal.service.StocksectorBiz;

import java.util.HashMap;
import java.util.List;

@Service("stocksectorBiz")
public class StocksectorBizImpl implements StocksectorBiz {
    @Autowired
    private StocksectorDao stocksectorDao;
    /**
     * 将基金实体添加数据库基金表中
     *
     * @param stocksector 基金对象
     * @return 0:添加失败,1:添加成功
     */
    @Override
    public int add(Stocksector stocksector) {
        return stocksectorDao.add(stocksector);
    }

    /**
     * 从表中根据基金编号字符串删除一行数据
     * @param stockId 基金编号字符串
     * @return 删除影响的行数(0 : 删除失败, 1 : 删除成功)
     */
    @Override
    public int delete(String stockId) {
        if(stockId.contains(",")){
            String[] strs=stockId.split(",");
            for(String str:strs){
                stocksectorDao.delete(Integer.parseInt(str));
            }
            return 1;
        }
        return stocksectorDao.delete(Integer.parseInt(stockId));
    }

    /**
     * 修改数据到foundation表
     *
     * @param stocksector 员工对象
     * @return 0:修改失败,1:修改成功
     */
    @Override
    public int update(Stocksector stocksector) {
        return stocksectorDao.update(stocksector);
    }

    /**
     * 按条件分页查询
     * @param stocksector
     * @param row
     * @param page
     * @return
     */
    @Override
    public List<Stocksector> queryAll(Stocksector stocksector, int row, int page) {
        HashMap<String,Object> map=new HashMap<>();
        map.put("stocksector",stocksector);
        map.put("start",page);
        map.put("end",(page+row));
        return stocksectorDao.queryAll(map);
    }

    /**
     * 按条件统计记录数
     *
     * @param stocksector 统计条件
     * @return 记录行数据
     */
    @Override
    public int count(Stocksector stocksector) {
        return stocksectorDao.count();
    }
}
